package test41;

import java.io.*;
import java.util.Deque;
import java.util.LinkedList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-05-13
 * Time: 16:24
 */
//https://www.nowcoder.com/questionTerminal/1a92fbc771a54feb9eb5bd9b3ff2d0a9
public class Main1 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String str = null;
        while ((str = br.readLine()) != null) {
            int len = Integer.parseInt(str);
            String[] arr = br.readLine().split(" ");
            Deque<Integer> stack = new LinkedList<>();
            for (int i = 0; i < len; i++) {
                if (!isOperate(arr[i])) {
                    stack.push(Integer.parseInt(arr[i]));
                } else {
                    int num2 = stack.pop();
                    int num1 = stack.pop();
                    String temp = arr[i];
                    switch (temp) {
                        case "+":
                            num1 += num2;
                            break;
                        case "-":
                            num1 -= num2;
                            break;
                        case "*":
                            num1 *= num2;
                            break;
                        case "/":
                            num1 /= num2;
                            break;
                    }
                    stack.push(num1);
                }
            }
            bw.write(stack.pop() + "\n");
        }
        bw.flush();
        bw.close();
        br.close();
    }

    public static boolean isOperate(String str) {
        char c =str.charAt(0);
        return str.length() == 1 && c == '-' || c == '+' || c == '*' || c == '/';
    }
}
